//      presentation_window.cpp

/*** TO-DO:
 * 1. Можно делать интерфейс для "ядра"
 */

#include <presentation_window.h>


PresentationWindow::PresentationWindow(QMainWindow* startWindow,
                                                                                QVector<qreal> pc,
                                                                                QVector<qreal> se,
                                                                                QWidget* parent)
    : QWidget(parent), startWindow(startWindow)
{
    setupUi(this);

    initGraph = new GraphScene();
    initGraphPage = new InitGraphPage();
    initGraphPage->setScene(initGraph);

    core = new Core(pc, se);
    QVector<quint16> vertex = core->calculate();
    resultPage = new ResultPage(core->getTotalExpenses(), core->getProdactLine());  
    resultGraph = new GraphScene(&vertex);
    resultPage->setScene(resultGraph);

    makeLastStepPage();
    makeSecondStepPage();
    makeFirstStepPage();

    stackedWidget = new QStackedWidget();
    verticalLayout->insertWidget(0, stackedWidget);
    // MakePages
    stackedWidget->addWidget(initGraphPage);
    stackedWidget->addWidget(lastStepPage);
    stackedWidget->addWidget(secondStepPage);
    stackedWidget->addWidget(firstStepPage);
    stackedWidget->addWidget(resultPage);
    stackedWidget->setCurrentIndex(0);
    prevButton->hide();
}

void PresentationWindow::toStartWindow()
{
    this->close();
    startWindow->show();

}

void PresentationWindow::moveToCenter()
{
    QPoint center = QDesktopWidget().availableGeometry().center();
    move(center - rect().center());
}

void PresentationWindow::toPrevPage()
{
    int index = stackedWidget->currentIndex();
    stackedWidget->setCurrentIndex(--index);
    nextButton->show();
    if (index == 0)
    {
        prevButton->hide();
    }
}

void PresentationWindow::toNextPage()
{
    int index = stackedWidget->currentIndex();
    stackedWidget->setCurrentIndex(++index);
    prevButton->show();
    if (index == stackedWidget->count() - 1)
    {
        nextButton->hide();
    }
}

void PresentationWindow::makeLastStepPage()
{
    lastStepPage = new LastStepPage(core->getLastStepValues());
}

void PresentationWindow::makeSecondStepPage()
{   QVector<qreal> mass;
    QVector<qreal> w2;
    QVector<quint32> s2;
    QVector<quint32> u2;
    core->getSecondStepValues(&mass, &w2, &s2, &u2);
    secondStepPage = new SecondStepPage(mass, w2, s2, u2);
}

void PresentationWindow::makeFirstStepPage()
{
    QVector<qreal> mass;
    qreal w1;
    quint32 s1;
    quint32 u1;
    core->getFirstStepValues(&mass, &w1, &s1, &u1);
    firstStepPage = new FirstStepPage(mass, w1, s1, u1);
}
